extends Node
var utils = globalData.infoDs["g_azurlaneUtils"]
class Info:
	var id = ""
	var base = null
	var evos = []
	var lv = 1
	var dir = ""
	var hide = false
	var type = ""
	var shipType = ""
	var name = ""
	var camp = ""
	
var infoDs = {}
var infos = []

var rndPool: = RndPool.new()
#全部基础角色
var rndPoolRal = []
#本局游戏基础角色
var rndPoolRsl = []

var infosLv1 = []
var infosLv2 = []
var infosLv3 = []
var infosLv4 = []

#装的是info
var upChas = []

#装的是info
var shipTypeDic = {
	sys.CharaClass.DD:[],
	sys.CharaClass.CL:[],
	sys.CharaClass.CA:[],
	sys.CharaClass.BB:[],
	sys.CharaClass.CV:[],
	sys.CharaClass.CVL:[],
	sys.CharaClass.SS:[],
	sys.CharaClass.SUP:[],
}

var shipCampDic = {}

func _ready():
	pass

#进入游戏后执行次函数
func init():
	for i in infos:
		infoDs[i.id] = i
		if i.hide == false and i.type == sys.CharaType.NORMAL:
			match i.lv:
				1:
					infosLv1.append(i)
					rndPoolRal.append(i.id)
				2: infosLv2.append(i)
				3: infosLv3.append(i)
				4: infosLv4.append(i)

#开始游戏时调用此函数初始化角色随机池
func rndPoolRs():
	rndPool.clear()
	var rd = [9, 3, 1, 0]
	for i in infos:
		if i.type == sys.CharaType.NORMAL:
			var bl = false
			for j in rndPoolRsl:
				if i.dir == infoDs[j].dir and rndPoolRsl.has(getLvIds(i.id, 1)): 
					rndPool.addItem(i, rd[i.lv - 1])

func loadInfoEx(dname, dir, infoType = null):
	var info = Info.new()
	info.id = dname
	info.lv = 1
	info.dir = dir
	info.type = infoType
	if info.id.find("Hide") != - 1:info.hide = true
	infos.append(info)

#一次性加载一整个角色树
func loadInfoF(arrs, infoType = null):
	var dict = {}
	var shipType = ""
	var cha = utils.newChara(arrs[0].name, 1, arrs[0].dir)
	cha._extInit()
	shipType = cha.type
	var camp = cha.get("camp")
	cha.queue_free()
	for i in arrs:
		var info = Info.new()
		info.id = i.name
		if infoType != sys.CharaType.SUMM and i.name.find("-") > -1:
			info.lv = int(i.name.split("-")[1])
		info.dir = i.dir
		info.type = infoType
		info.shipType = shipType
		info.camp = camp
		info.name = cha.chaName
		if info.id.find("Hide") != - 1:info.hide = true
		infos.append(info)	
		
		infoDs[info.id] = info
		if info.hide == false and info.type == sys.CharaType.NORMAL:
			match info.lv:
				1:
					infosLv1.append(info)
					rndPoolRal.append(info.id)
				2: infosLv2.append(info)
				3: infosLv3.append(info)
				4: infosLv4.append(info)

		dict[info.lv] = info
		if info.lv == 1 and (infoType == sys.CharaType.NORMAL):
			shipTypeDic.get(shipType).append(info)
		if info.lv == 1 and info.camp != "塞壬" and infoType != sys.CharaType.SUMM:
			utils.dicAppend(shipCampDic, info.camp, info)

		if info.id.find("plane-") > -1:
			loadPlane(info.id)
		if infoType == sys.CharaType.UP and info.lv == 1:
			upChas.append(info)

	for info in dict.values():
		if dict.has(info.lv - 1):
			info.base = dict.get(info.lv - 1)
		if dict.has(info.lv + 1):
			info.evos.append(dict.get(info.lv + 1))

func reSet():
	infos.clear()
	infoDs.clear()
	rndPoolRal.clear()
	rndPoolRsl.clear()
	rndPool.clear()
	
func getBaseId(id):
	if infoDs[id].base != null:
		return infoDs[id].base.id
	else :return id

func getLvIds(id, lv):
	var info = infoDs[id]
	if info.lv > lv:
		while info.base != null and info.id != "" and info.lv > lv:
			info = info.base
	else:
		while not info.evos.empty() and info.id != "" and info.lv < lv:
			info = info.evos[0]
	if info.id == "":info.id = id
	return info.id
	
func getEvoIds(id):
	var ids = []
	for i in infoDs[id].evos:
		ids.append(i.id)
	return ids

var lv = 0
func rndLvInfo(lv):
	self.lv = lv
	return rndPool.rndItem(self, "isLv")
func isLv(obj):
	if obj.lv == lv:return true
	return false



#普通舰载机
var planes = {}
#稀有舰载机
var planesRare = {}

func loadPlane(id):
	var cha = utils.newChara(id)
	cha._extInit()
	if cha.lv == 2:
		planes[id] = {"name": cha.chaName, "skills": cha.skillStrs}
	elif cha.lv == 3:
		planesRare[id] = {"name": cha.chaName, "skills": cha.skillStrs}

func getRndPlane(rare = false):
	if rare:
		return sys.rndListItem(planesRare.keys())
	else:
		return sys.rndListItem(planes.keys())

func getPlaneInfo(id):
	if planes.has(id):
		return planes.get(id)
	else:
		return planesRare.get(id)